<?php
include_once("../includes/common.php");
include_once("../class/User.class.php");
include_once("../class/Action.class.php");
require_once("../islogin.php");

if ($isadmin!=1){
    header('Location: /');
    exit;
}

$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];
$pageName = "搜索热词操控";

$action = new Action();

if(isset($_GET['search'])&&$_GET['num']){
    $res = $action->addSearchKey($_GET['search'],$_GET['num']);

    $referrer = $_SERVER['HTTP_REFERER'];
    header("Location: $referrer");
    exit();
}

$searchHot = json_decode($action->getTodayHotSearch(),true);
if (isset($_GET['del'])) {
    $action->delSearchKey($_GET['del']);
    $referrer = $_SERVER['HTTP_REFERER'];
    header("Location: $referrer");
    exit();
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

    <?php require_once('head.php'); ?>

</head>
<body>

<!--==================== Preloader Start ====================-->
<div class="preloader">
    <div class="loader"></div>
</div>
<!--==================== Preloader End ====================-->

<!--==================== Sidebar Overlay End ====================-->
<div class="side-overlay"></div>
<!--==================== Sidebar Overlay End ====================-->


<?php require_once('menu.php'); ?>
<div class="dashboard-main-wrapper">

    <?php require_once('top_navbar.php'); ?>
    <div class="dashboard-body">
        <!-- My Details Tab start -->
        <div class="tab-pane fade show active" id="pills-details" role="tabpanel" aria-labelledby="pills-details-tab" tabindex="0">
            <div class="card">
                <div class="card-header border-bottom">
                    <h4 class="mb-4"><?php echo $pageName?></h4>
                </div>
                <div class="card-body">
                    <form action="" method="get">
                        <div class="row gy-4">
                            <div class="col-sm-12 col-xs-12">
                                <label for="fname" class="form-label mb-8 h6">输入要上榜的热词</label>
                                <input type="text" required maxlength="100" value="<?php echo $_GET['search']?>" name="search" class="form-control py-11" id="fname" placeholder="输入热搜关键词">
                            </div>
                            <div class="col-sm-12 col-xs-12">
                                <label for="fname" class="form-label mb-8 h6">增加搜索次数</label>
                                <input type="number" required max="10000" value="" name="num" class="form-control py-11" id="fname" placeholder="输入搜索次数(最大10000一次)">
                            </div>
                            <div class="col-12">
                                <div class="flex-align justify-content-end gap-8">
                                    <button type="submit" class="btn btn-main rounded-pill py-9">上榜</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- My Details Tab End -->

        <div class="card mt-24">
            <div class="card-header border-bottom">
                <div class="flex-between flex-wrap  gap-16">
                    <div>
                        <h4 class="mb-4">今日热搜</h4>
                    </div>
                </div>
            </div>


            <div class="card-body p-0 overflow-x-auto">
                <div id="studentTable_wrapper" class="dt-container dt-empty-footer"><div class="dt-layout-row"><div class="dt-layout-cell dt-start "></div><div class="dt-layout-cell dt-end "></div></div><div class="dt-layout-row dt-layout-table"><div class="dt-layout-cell "><table id="studentTable" class="table table-lg table-striped w-100 dataTable" style="width: 0px;"><colgroup><col data-dt-column="0" style="width: 0px;"><col data-dt-column="1" style="width: 0px;"><col data-dt-column="2" style="width: 0px;"><col data-dt-column="3" style="width: 0px;"><col data-dt-column="4" style="width: 0px;"><col data-dt-column="5" style="width: 0px;"><col data-dt-column="6" style="width: 0px;"></colgroup>
                                <thead>
                                <tr role="row"><th class="h6 text-gray-600 dt-orderable-asc dt-orderable-desc" data-dt-column="1" rowspan="1" colspan="1" aria-label="

                                                Invoices

                                        : Activate to sort" tabindex="0"><span class="dt-column-title" role="button">
                                            <span class="position-relative">
                                                搜索词
                                            </span>
                                        </span><span class="dt-column-order"></span></th>
                                    <th class="h6 text-gray-600 text-center dt-type-numeric dt-orderable-asc dt-orderable-desc" data-dt-column="2" rowspan="1" colspan="1" aria-label="Amount: Activate to sort" tabindex="0"><span class="dt-column-title" role="button">次数</span><span class="dt-column-order"></span></th>

                                    <th class="h6 text-gray-600 text-center dt-type-numeric dt-orderable-asc dt-orderable-desc" data-dt-column="2" rowspan="1" colspan="1" aria-label="操作" tabindex="0"><span class="dt-column-title" role="button">操作</span><span class="dt-column-order"></span></th>
                                    </tr>
                                </thead>
                                <tbody>

                                <?php foreach ($searchHot as $item): ?>
                                <tr>
                                    <td>
                                        <div class="flex-align gap-10">
                                            <div class="">
                                                <span class="text-23 fw-medium text-gray-200"><?php echo htmlspecialchars($item['search_keywords']);?></span>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="text-center dt-type-numeric">
                                        <span class="text-gray-600"><?php echo $item['search_count']?></span>
                                    </td>
                                    <td class="text-center">
                                        <a href="?search=<?php echo htmlspecialchars($item['search_keywords']);?>" type="button" class="btn btn-outline-main bg-main-100 border-main-100 text-main-600 rounded-pill py-12">上榜</a>
                                        <a onclick="return confirm('下榜后将会清空该关键词的搜索记录！');" href="?del=<?php echo htmlspecialchars($item['search_keywords']);?>" type="button" class="btn btn-outline-danger bg-danger-100 border-danger-100 text-danger-600 rounded-pill py-12">一键下榜</a>


                                    </td>
                                </tr>

                                <?php endforeach; ?>
                                </tbody>
                                <tfoot></tfoot></table></div></div><div class="dt-layout-row"><div class="dt-layout-cell dt-start "></div><div class="dt-layout-cell dt-end "></div></div></div>
            </div>
        </div>



    </div>

    <?php require_once('footer.php'); ?>
</div>

<?php require_once('foot.php'); ?>



</body>
</html>